<div class="card mb-4">
  <div class="card-header d-flex justify-content-between px-3">
    <h5 class="card-title">
      <%= icon('checklist', class: 'mr-2') %>
      <%= Spree.t(:rules) %>
    </h5>
    <% if can?(:create, Spree::PromotionRule.new(promotion: @promotion)) %>
      <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-primary btn-sm', data: { turbo_frame: 'dialog', action: 'dialog#open' } %>
    <% end %>
  </div>
  <div class="card-body">
    <div class="form-group mb-0">
      <div class="d-block d-lg-flex gap-3">
        <%= form_with model: @promotion, url: spree.admin_promotion_path(@promotion), method: :put, data: { controller: 'auto-submit' } do |f| %>
          <% Spree::Promotion::MATCH_POLICIES.each do |policy| %>
            <div class="custom-control custom-radio custom-control-inline">
              <%= f.radio_button :match_policy, policy, class: 'custom-control-input', data: { action: 'auto-submit#submit' } %>
              <%= f.label "match_policy_#{policy}", class: 'custom-control-label' %>
            </div>
          <% end %>
        <% end %>
      </div>
    </div>
  </div>
  <div class="card-body p-2 d-flex flex-column gap-2">
    <% if @promotion.promotion_rules.empty? %>
      <div class="text-muted p-5 d-flex align-items-center w-100 justify-content-center">
        <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::PromotionRule)) %>
        <% if can?(:create, Spree::PromotionRule.new(promotion: @promotion)) %>
          <%= link_to_with_icon 'plus', Spree.t(:add_one), spree.new_admin_promotion_rule_path(@promotion), class: 'btn btn-light btn-sm ml-3', data: { turbo_frame: 'dialog', action: 'dialog#open' } %>
        <% end %>
      </div>
    <% else %>
      <%= render collection: @promotion.promotion_rules, 
                 partial: 'spree/admin/promotion_rules/promotion_rule', 
                 as: :promotion_rule,
                 cached: spree_base_cache_scope %>
    <% end %>
  </div>
</div>
